package org.hawk.gwtppc.webtest.tests.methodsuite;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.TypeVariable;
import java.util.RandomAccess;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.GenericClassMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock2;

public class GetTypeParametersTest implements Test {

	public void run() throws Throwable {
		TypeVariable<Method>[] vars1 = GenericClassMock.class.getDeclaredMethod("getSomeValue", Object.class, Object.class, Class.class).getTypeParameters();
		Asserts.assertEquals(vars1.length, 1);
		Asserts.assertEquals(vars1[0].getName(), "T");
		Asserts.assertEquals(vars1[0].getBounds().length, 1);
		Asserts.assertEquals(vars1[0].getBounds()[0], Object.class);
		
		TypeVariable<Method>[] vars2 = GenericClassMock.class.getDeclaredMethod("getThirdValue", CharSequence.class, RandomAccess.class).getTypeParameters();
		Asserts.assertEquals(vars2.length, 2);
		Asserts.assertEquals(vars2[0].getName(), "T1");
		Asserts.assertEquals(vars2[0].getBounds().length, 1);
		Asserts.assertEquals(vars2[0].getBounds()[0], CharSequence.class);
		Asserts.assertEquals(vars2[1].getName(), "T2");
		Asserts.assertEquals(vars2[1].getBounds().length, 2);
		Asserts.assertEquals(vars2[1].getBounds()[0], RandomAccess.class);
		Asserts.assertEquals(vars2[1].getBounds()[1], Serializable.class);
		
		Asserts.assertEquals(GenericClassMock.class.getDeclaredMethod("getOtherValue", CharSequence.class).getTypeParameters().length, 0);
		Asserts.assertEquals(SubClassMock2.class.getDeclaredMethod("processValue").getTypeParameters().length, 0);
	}

	public String getName() {
		return "getTypeParameters()";
	}

}